/*
Logfile Class
*/

#ifndef PGLOG_H
#define PGLOG_H

#include <Windows.h>
#include <stdio.h>
#include"PaleGem.h"
#include<string>
#include"Singleton.h"

#define MAX_BUFFER 1024

#define g_PG_pLog g_PG_pPaleGemFramework->GetLogfile()

// Log an error to the log, errors always get logged
#define PG_LOG_ERROR(msg, hr, file, line)	{g_PG_pLog->fTextout(RED, false,  "ERROR: %s Error code: %d(File: %s, Line: %d) \n", msg, hr, file, line);}
// Log an errror to the log, errors always get logged
#define PG_LOG_ERROR_SIMPLE(msg, hr)		{g_PG_pLog->fTextout(RED, false, "ERROR: %s Error code: %d \n", msg, hr);}
// Log an error with a DX HRESULT to the log (prints error description)
// Errors always get logged
#define PG_DX_LOG_ERROR(hr, file, line)		{g_PG_pLog->fTextout(RED, false, "DirectX ERROR: %s (code: %d) (File: %s, Line %d) \n", DXGetErrorDescriptionA(hr), hr, file, line);}
// Log a warning to the log, warnings always get logged
#define PG_LOG_WARNING_EX(topic, msg, ...)	{g_PG_pLog->LogWarning(topic, msg, __VA_ARGS__);}
// Log an info to the log, only when verbosity is set to ALL
#define PG_LOG_INFO_EX(topic, msg, ...)		{if (g_PG_pLog->GetVerbosityLevel() == ALL) g_PG_pLog->fTextoutTopic(GREEN, topic, msg, __VA_ARGS__);}
// Log an info to the log, this always gets logged
#define PG_LOG_ALWAYS_EX(topic, msg, ...)	{g_PG_pLog->fTextoutTopic(GREEN, topic, msg, __VA_ARGS__);}

// Topic definitions
#define TOPIC_PGGAME_APP			"pgPaleGemFramework"
#define TOPIC_PGRENDERER			"pgRenderer"
#define TOPIC_PGTIMER				"pgTimer"
#define TOPIC_PGMATERIAL			"pgMaterial"
#define TOPIC_PGEVENT_MANAGER		"pgEventManager"
#define TOPIC_FBXLOADER				"FBX Loader"
#define TOPIC_OBJLOADER				"pgOBJLoader"
#define TOPIC_INPUT_EVENT_MANAGER	"pgInputEventManager"
#define TOPIC_MOUSE_INPUT_MANAGER	"pgMouseInputManager"

#include"IEventListener.h"


enum FONTCOLORS
{
	BLACK,
	RED,
	GREEN,
	BLUE,
	PURPLE,
	YELLOW,
};

enum EVERBOSITY_LEVEL
{
	RELEASE,
	ALL,
};

class PALEGEM_API CLogfile
{
public:
	CLogfile();
	~CLogfile();


	// Creates a logfile with the specified filename
	int CreateLogfile(const char* sFilename);
	//Starts a new topic in the logfile	
	void WriteTopic	(const char* sTopic, int size);		
	// Writes some simple textstring
	void Textout	(const char* sText);				
	// Writes simple text in the specified color
	void Textout	(int Color, const char* sText);		
	//Writes simple text in the specified color and if need a list
	void Textout	(int Color, bool bList, const char* sText);		
	// Writes a formatted string
	void fTextout	(const char* sText,...);	
	// Writes a colored formatted string
	void fTextout	(int Color, const char* sText,...);	
	// Writes a colored formatted string and if needed a list
	void fTextout	(int Color, bool bList, const char* sText,...);	
	// Writes the result of a function into the log
	void FunctionResult (const char* sName, bool bResult);
	// Writes the text under the specified topic
	void fTextoutTopic (const char* sTopic, const char* sText,...);
	// Writes the colored text under the specified topic
	void fTextoutTopic (int Color, const char* sTopic, const char* sText, ...);
	// Set the verbosity level
	void SetVerbosity(EVERBOSITY_LEVEL level) {m_verbosityLevel = level;}
	// Get verbosity level
	EVERBOSITY_LEVEL GetVerbosityLevel() {return m_verbosityLevel;}
	// Log a warning
	void LogWarning(const char* szTopic, const char* szWarning, ...);

private:

	// The file handle pointer
	FILE* m_pLogfile;
	// Textbuffer
	std::string m_sWholeText;
	// Filename of log
	const char* m_sFilename;
	// Level of verbosity
	EVERBOSITY_LEVEL m_verbosityLevel;
	
};

#endif